namespace Ds.DataBase.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class _20200702001 : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.KeShiZhiWeis", "KeShi_ksid", "dbo.KeShis");
            DropForeignKey("dbo.KeShiZhiWeis", "ZhiWei_zwid", "dbo.ZhiWeis");
            DropForeignKey("dbo.MoBan_MainZhiWei", "MoBan_Main_mbid", "dbo.MoBan_Main");
            DropForeignKey("dbo.MoBan_MainZhiWei", "ZhiWei_zwid", "dbo.ZhiWeis");
            DropForeignKey("dbo.PowerTreeZhiWeis", "PowerTree_ptid", "dbo.PowerTrees");
            DropForeignKey("dbo.PowerTreeZhiWeis", "ZhiWei_zwid", "dbo.ZhiWeis");
            DropForeignKey("dbo.JiaoZhiGongInfoes", "zw_zwid", "dbo.ZhiWeis");
            DropIndex("dbo.JiaoZhiGongInfoes", new[] { "zw_zwid" });
            DropIndex("dbo.KeShiZhiWeis", new[] { "KeShi_ksid" });
            DropIndex("dbo.KeShiZhiWeis", new[] { "ZhiWei_zwid" });
            DropIndex("dbo.MoBan_MainZhiWei", new[] { "MoBan_Main_mbid" });
            DropIndex("dbo.MoBan_MainZhiWei", new[] { "ZhiWei_zwid" });
            DropIndex("dbo.PowerTreeZhiWeis", new[] { "PowerTree_ptid" });
            DropIndex("dbo.PowerTreeZhiWeis", new[] { "ZhiWei_zwid" });
            CreateTable(
                "dbo.KeShiZhiWus",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        KeShi_ksid = c.Int(),
                        zhiwu_zwid = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.KeShis", t => t.KeShi_ksid)
                .ForeignKey("dbo.ZhiWeis", t => t.zhiwu_zwid)
                .Index(t => t.KeShi_ksid)
                .Index(t => t.zhiwu_zwid);
            
            AddColumn("dbo.ZhiWeis", "MoBan_Main_mbid", c => c.Int());
            AddColumn("dbo.ZhiWeis", "PowerTree_ptid", c => c.Int());
            AddColumn("dbo.JiaoZhiGongInfoes", "KeShiZhiWu_id", c => c.Int());
            AddColumn("dbo.MoBan_Main", "KeShiZhiWu_id", c => c.Int());
            AddColumn("dbo.PowerTrees", "KeShiZhiWu_id", c => c.Int());
            AlterColumn("dbo.JiaoZhiGongInfoes", "zw_zwid", c => c.Int());
            CreateIndex("dbo.ZhiWeis", "MoBan_Main_mbid");
            CreateIndex("dbo.ZhiWeis", "PowerTree_ptid");
            CreateIndex("dbo.JiaoZhiGongInfoes", "KeShiZhiWu_id");
            CreateIndex("dbo.JiaoZhiGongInfoes", "zw_zwid");
            CreateIndex("dbo.MoBan_Main", "KeShiZhiWu_id");
            CreateIndex("dbo.PowerTrees", "KeShiZhiWu_id");
            AddForeignKey("dbo.JiaoZhiGongInfoes", "KeShiZhiWu_id", "dbo.KeShiZhiWus", "id");
            AddForeignKey("dbo.ZhiWeis", "MoBan_Main_mbid", "dbo.MoBan_Main", "mbid");
            AddForeignKey("dbo.MoBan_Main", "KeShiZhiWu_id", "dbo.KeShiZhiWus", "id");
            AddForeignKey("dbo.ZhiWeis", "PowerTree_ptid", "dbo.PowerTrees", "ptid");
            AddForeignKey("dbo.PowerTrees", "KeShiZhiWu_id", "dbo.KeShiZhiWus", "id");
            AddForeignKey("dbo.JiaoZhiGongInfoes", "zw_zwid", "dbo.ZhiWeis", "zwid");
            DropTable("dbo.KeShiZhiWeis");
            DropTable("dbo.MoBan_MainZhiWei");
            DropTable("dbo.PowerTreeZhiWeis");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.PowerTreeZhiWeis",
                c => new
                    {
                        PowerTree_ptid = c.Int(nullable: false),
                        ZhiWei_zwid = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.PowerTree_ptid, t.ZhiWei_zwid });
            
            CreateTable(
                "dbo.MoBan_MainZhiWei",
                c => new
                    {
                        MoBan_Main_mbid = c.Int(nullable: false),
                        ZhiWei_zwid = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.MoBan_Main_mbid, t.ZhiWei_zwid });
            
            CreateTable(
                "dbo.KeShiZhiWeis",
                c => new
                    {
                        KeShi_ksid = c.Int(nullable: false),
                        ZhiWei_zwid = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.KeShi_ksid, t.ZhiWei_zwid });
            
            DropForeignKey("dbo.JiaoZhiGongInfoes", "zw_zwid", "dbo.ZhiWeis");
            DropForeignKey("dbo.KeShiZhiWus", "zhiwu_zwid", "dbo.ZhiWeis");
            DropForeignKey("dbo.PowerTrees", "KeShiZhiWu_id", "dbo.KeShiZhiWus");
            DropForeignKey("dbo.ZhiWeis", "PowerTree_ptid", "dbo.PowerTrees");
            DropForeignKey("dbo.MoBan_Main", "KeShiZhiWu_id", "dbo.KeShiZhiWus");
            DropForeignKey("dbo.ZhiWeis", "MoBan_Main_mbid", "dbo.MoBan_Main");
            DropForeignKey("dbo.KeShiZhiWus", "KeShi_ksid", "dbo.KeShis");
            DropForeignKey("dbo.JiaoZhiGongInfoes", "KeShiZhiWu_id", "dbo.KeShiZhiWus");
            DropIndex("dbo.PowerTrees", new[] { "KeShiZhiWu_id" });
            DropIndex("dbo.MoBan_Main", new[] { "KeShiZhiWu_id" });
            DropIndex("dbo.KeShiZhiWus", new[] { "zhiwu_zwid" });
            DropIndex("dbo.KeShiZhiWus", new[] { "KeShi_ksid" });
            DropIndex("dbo.JiaoZhiGongInfoes", new[] { "zw_zwid" });
            DropIndex("dbo.JiaoZhiGongInfoes", new[] { "KeShiZhiWu_id" });
            DropIndex("dbo.ZhiWeis", new[] { "PowerTree_ptid" });
            DropIndex("dbo.ZhiWeis", new[] { "MoBan_Main_mbid" });
            AlterColumn("dbo.JiaoZhiGongInfoes", "zw_zwid", c => c.Int(nullable: false));
            DropColumn("dbo.PowerTrees", "KeShiZhiWu_id");
            DropColumn("dbo.MoBan_Main", "KeShiZhiWu_id");
            DropColumn("dbo.JiaoZhiGongInfoes", "KeShiZhiWu_id");
            DropColumn("dbo.ZhiWeis", "PowerTree_ptid");
            DropColumn("dbo.ZhiWeis", "MoBan_Main_mbid");
            DropTable("dbo.KeShiZhiWus");
            CreateIndex("dbo.PowerTreeZhiWeis", "ZhiWei_zwid");
            CreateIndex("dbo.PowerTreeZhiWeis", "PowerTree_ptid");
            CreateIndex("dbo.MoBan_MainZhiWei", "ZhiWei_zwid");
            CreateIndex("dbo.MoBan_MainZhiWei", "MoBan_Main_mbid");
            CreateIndex("dbo.KeShiZhiWeis", "ZhiWei_zwid");
            CreateIndex("dbo.KeShiZhiWeis", "KeShi_ksid");
            CreateIndex("dbo.JiaoZhiGongInfoes", "zw_zwid");
            AddForeignKey("dbo.JiaoZhiGongInfoes", "zw_zwid", "dbo.ZhiWeis", "zwid", cascadeDelete: true);
            AddForeignKey("dbo.PowerTreeZhiWeis", "ZhiWei_zwid", "dbo.ZhiWeis", "zwid", cascadeDelete: true);
            AddForeignKey("dbo.PowerTreeZhiWeis", "PowerTree_ptid", "dbo.PowerTrees", "ptid", cascadeDelete: true);
            AddForeignKey("dbo.MoBan_MainZhiWei", "ZhiWei_zwid", "dbo.ZhiWeis", "zwid", cascadeDelete: true);
            AddForeignKey("dbo.MoBan_MainZhiWei", "MoBan_Main_mbid", "dbo.MoBan_Main", "mbid", cascadeDelete: true);
            AddForeignKey("dbo.KeShiZhiWeis", "ZhiWei_zwid", "dbo.ZhiWeis", "zwid", cascadeDelete: true);
            AddForeignKey("dbo.KeShiZhiWeis", "KeShi_ksid", "dbo.KeShis", "ksid", cascadeDelete: true);
        }
    }
}
